﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

public partial class VerifyJob : System.Web.UI.Page
{
    string groupName;
    string empID;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userinfo"] == null)
        {
            Response.Redirect("Default.aspx");
            return;
        }
        if (Session["IsAdmin"].ToString().ToLower() == "false")
            return;
        groupName = Session["GroupName"].ToString();
        empID = Session["EmpID"].ToString();
        if (!IsPostBack)
        {
            
            GetVerifyJobList();
            if (gvVerifyJobList.Rows.Count != 0)
            {
                DVNoData.Visible = false;
            }
            else
            {
                DVNoData.Visible = true;
            }
        }

        
    }
    protected void GetVerifyJobList()
    {
        DBOperate myDB = new DBOperate();
        string cmd = string.Format(@"SELECT DISTINCT ViewLog.[No], DataList.Item, ViewLog.EmpID, UserList.EmpName, ViewLog.VisitTimes
                                    FROM ((DataList INNER JOIN
                                                    ViewLog ON ViewLog.DataNo = DataList.[No]) INNER JOIN
                                                    UserList ON ViewLog.EmpID = UserList.EmpID)
                                    WHERE(ViewLog.NeedConfirm = true) AND (ViewLog.CThisJob = false) AND UserList.GroupName = '{0}'",groupName);
        myDB.SetCommandString(cmd);
        gvVerifyJobList.DataSource = myDB.ExecuteReader();
        gvVerifyJobList.DataBind();
        myDB.CloseDB();
    }

    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        GridViewRow row = ((Button)sender).NamingContainer as GridViewRow; //得到点击更新的行号
        string cmd = string.Format(@"Update ViewLog set CThisJob = true,CEmpID = '{0}',CDate = '{1}'
                                        where [No]={2}", 
                                   empID,
                                   DateTime.Now.ToString("yyyy-MM-dd"),
                                   row.Cells[0].Text);
        DBOperate myDB = new DBOperate();
        myDB.SetCommandString(cmd);
        myDB.ExecuteNonReader();
        myDB.CloseDB();
        GetVerifyJobList();
    }
}
